import get_params from '@dfeidao/atom-nodejs/authorization/get-params';
import { ICommonParams, IHeaders } from '@dfeidao/atom-nodejs/interfaces';
import log from '@dfeidao/atom-nodejs/logger/log';
import whoami from '@dfeidao/atom-nodejs/msg/whoami';
import { IncomingHttpHeaders } from 'http';

interface Message {
	filter: { productid: string };
	page_size: number;
	page_no: number;
	// cookie: {
	// 	uk: string;
	// 	[key: string]: string
	// };
	// urls: {
	// 	base: string;
	// 	origin: string;
	// 	url: string;
	// };
	// query: {};
	// params: {};
	// headers: {};
	// captcha: string;
}

interface IWebResult {
	data: unknown;
	cookie?: {
		[name: string]: string;
	} | null;
	content_type?: string;
	headers?: {
		[key: string]: string[];
	};
	attachment?: string;
	redirect?: string;
	status_code?: number;
}

export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders): Promise<IWebResult> {
	log('Service begin path:d:\gitee-new\teach_sys-web-h5-wxapp\w000004\src\atom\s001,action_id:' + action_id);
	const userinfo = await whoami(action_id, session_id);

	const msg = {
		cookie: { sessionid: session_id },
		data: {},
		headers: {},
		params: {},
		query: {},
		remote_address: '',
		spaceid: "",
		url: ""
	} as ICommonParams;
	const hearders = {
		actionid: action_id
	} as IHeaders;
	const productid = userinfo.productid;

	const params = await get_params(msg, hearders, productid, '1');
	log('Service end path:d:\gitee-new\teach_sys-web-h5-wxapp\w000004\src\atom\s001,action_id:' + action_id);
	return { data: { userinfo, params } } as IWebResult;
}
